package src.main.java.org.Arrays;

import java.util.Arrays;
import java.util.function.IntToDoubleFunction;

public class ArrayTest1 {
    public static void main(String[] args) {
        //1.public static String toString(类型[] arr)；返回数组的内容
        int[] arr = {10,20,30,40,50};
        System.out.println(Arrays.toString(arr));
        //2.public static int[] copyOfRange(类型[] arr，起始索引，结束索引)：拷贝数组（指定范围，包前不包后）
        int[] ints = Arrays.copyOfRange(arr, 1, 4);
        System.out.println(Arrays.toString(ints));
        //3.public static copyOf(类型[],arr,int newLength)拷贝数组，可以指定新数组的长度。
        int[] ints1 = Arrays.copyOf(arr, 10);
        System.out.println(Arrays.toString(ints1));
        //4.public static setAll(double[] array,IntToDoubleFunction genrator),把数组中的原数据改为新数据存进去
        double[] prices = {99.8,129,100};
        Arrays.setAll(prices, new IntToDoubleFunction(){
            public double applyAsDouble(int value){
                return prices[value] *0.8;
            }
        });
        System.out.println(Arrays.toString(prices));
        //5.public static void sort(类型[] arr)，对数组进行排序（默认是升序排序）
        Arrays.sort(prices);
        System.out.println(Arrays.toString(prices));
    }
}
